package main

import (
	"bytes"
	"encoding/binary"
	"fmt"
	"strconv"
)

type head struct{
	CmdType uint8
	PacketLen uint32
	Version uint8
}

func main() {
	//endianTest()
}

func endianTest(){

	x := make([]byte, 0)
	x = append(x, []byte("AadsasqweasdQ")...)

	w := bytes.NewBuffer(make([]byte, 0,65535))
	msgLen := len(x)
	h := &head{4,uint32(msgLen),2}
	binary.Write(w,binary.BigEndian,h)
	fmt.Println(w.Len())
	fmt.Println(w.Bytes())
	w.Write(x)
	binary.Write(w,binary.BigEndian,h)
	w.Write(x)
	binary.Write(w,binary.BigEndian,h)
	w.Write(x)

	fmt.Println(w.Bytes())

	h2 := &head{}
	binary.Read(w,binary.BigEndian,h2)
	fmt.Println(h2)
	fmt.Println(string(w.Next(int(h2.PacketLen))))
	h2 = &head{}


	binary.Read(w,binary.BigEndian,h2)
	fmt.Println(h2)
	fmt.Println(string(w.Next(int(h2.PacketLen))))
	h2 = &head{}

	binary.Read(w,binary.BigEndian,h2)
	fmt.Println(h2)
	fmt.Println(string(w.Next(int(h2.PacketLen))))
	h2 = &head{}

	binary.Read(w,binary.BigEndian,h2)
	fmt.Println(h2)
	fmt.Println(string(w.Next(int(h2.PacketLen))))
	h2 = &head{}
}

func BufString(){
	var buf bytes.Buffer
	n, e := buf.WriteString("test")
	fmt.Println(n, e)
	count := 0
	for  {
		if count >= 10{
			break
		}
		count ++
		test := strconv.Itoa(count)
		buf.WriteString(test)
	}
	fmt.Println(buf.String())
}

